package com.jcode.netty.server;

import org.apache.commons.configuration.PropertiesConfiguration;

/**
 * @Author dreajay
 * @DateTime 2016年10月15日 上午11:15:40
 */
public class NettyServerMain {

    public static void main(String[] args) throws Exception {
        PropertiesConfiguration prop = new PropertiesConfiguration("config.properties");
        ServerConfig config = new ServerConfig();
        int start = prop.getInt("server.startPort");
        int end = prop.getInt("server.endPort");
        for (int i = start; i <= end; i++) {
            config.addListenPort(i);
        }
        config.setMaxConnectionSize(prop.getInt("server.maxConnectionSize"));

        config.setServerChannelMaxIdleTimeSeconds(prop.getInt("server.serverChannelMaxIdleTimeSeconds"));

        if(prop.containsKey("server.bindIp")) {
            config.setBindIp(prop.getString("server.bindIp"));
        }
        if(prop.containsKey("server.serverBossThreads")) {
            config.setServerBossThreads(prop.getInt("server.serverBossThreads"));
        }
        if(prop.containsKey("server.serverWorkerThreads")) {
            config.setServerWorkerThreads(prop.getInt("server.serverWorkerThreads"));
        }

        if(prop.containsKey("server.serverCallbackExecutorThreads")) {
            config.setServerCallbackExecutorThreads(prop.getInt("server.serverCallbackExecutorThreads"));
        }
        if(prop.containsKey("server.serverOnewaySemaphoreValue")) {
            config.setServerOnewaySemaphoreValue(prop.getInt("server.serverOnewaySemaphoreValue"));
        }
        if(prop.containsKey("server.serverAsyncSemaphoreValue")) {
            config.setServerAsyncSemaphoreValue(prop.getInt("server.serverAsyncSemaphoreValue"));
        }
        if(prop.containsKey("server.useEpollNativeSelector")) {
            config.setUseEpollNativeSelector(prop.getBoolean("server.useEpollNativeSelector"));
        }

        System.out.println("server start: " + config);

        NettyServer server = new NettyServer(config);
        server.start();
    }

}
